package com.app.enums;

/**
 * 监控应用场景 枚举
 */
public enum DeviceScenEnum {

    /**
     * 应用场景，默认0 未知、1 智慧交通、2 智慧环卫、3 智慧河道、4 明厨亮灶
     */
    SMART_TRANSPORTATION("智慧交通", 6),
    SMART_ENVIRONMENTAL_SANITATION("智慧环卫", 7),
    SMART_RIVER("智慧河道", 8),
    BRIGHT_KITCHEN_AND_STOVE("明厨亮灶", 9),
    UN_KNOWN("未知", 10);

    private final String name;
    private final Integer value;

    DeviceScenEnum(String role, Integer value) {
        this.name = role;
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public Integer getValue() {
        return value;
    }


    public static DeviceScenEnum valueOf(Integer value) {
        DeviceScenEnum periodEnum = null;
        try {
            periodEnum = getEnumByValue(DeviceScenEnum.class, value);
            System.out.println("找到的枚举: " + periodEnum);
        } catch (IllegalArgumentException e) {
            System.out.println(e.getMessage());
        }
        return periodEnum;
    }

    // 假设 FeedbackPeriodEnum 是上面定义的枚举类型
    private static <E extends Enum<E>> E getEnumByValue(Class<E> enumClass, int value) {
        for (E enumConstant : enumClass.getEnumConstants()) {
            if (((DeviceScenEnum) enumConstant).getValue() == value) {
                return enumConstant;
            }
        }
        throw new IllegalArgumentException("没有找到 value 为 " + value + " 的枚举实例");
    }

    public static void main(String[] args) {
        System.out.println(DeviceScenEnum.SMART_RIVER.value);
    }
}
